﻿namespace LS.Screening.UI.Common
{
    public class Keywords
    {
        /// <summary>
        /// 创建人
        /// </summary>
        public const string CreaterPropertyName = "Creater";

        /// <summary>
        /// 创建时间
        /// </summary>
        public const string CreateTimePropertyName = "CreateTime";

        /// <summary>
        /// 修改人
        /// </summary>
        public const string UpdaterPropertyName = "Updater";

        /// <summary>
        /// 修改时间
        /// </summary>
        public const string UpdateTimePropertyName = "UpdateTime";

        /// <summary>
        /// 所属组织
        /// </summary>
        public const string OrganizationIdPropertyName = "OrganizationId";

        /// <summary>
        /// 是否已删除
        /// </summary>
        public const string IsDeletedPropertyName = "IsDeleted";

        /// <summary>
        /// 数据行版本号字段
        /// </summary>
        public const string VersionPropertyName = "Version";

        /// <summary>
        /// 业务实体的关键字段
        /// </summary>
        public static string[] EntityKeyFields = new string[8] { "Id", "OrganizationId", "Version", "Creater", "CreateTime", "IsDeleted", "Updater", "UpdateTime" };

        /// <summary>
        /// 业务实体的关键字段
        /// </summary>
        public static string[] EntityIgnoreFields = new string[8] { "FirstTransData", "LastTransData", "Selected", "Status", "Master", "Key", "HasErrors", "Errors" };

        /// <summary>
        /// 是否框架关键字段
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public static bool IsKeyWord(string name)
        {
            return name.Equals("Creater", StringComparison.OrdinalIgnoreCase) || name.Equals("CreateTime", StringComparison.OrdinalIgnoreCase) || name.Equals("Updater", StringComparison.OrdinalIgnoreCase) || name.Equals("UpdateTime", StringComparison.OrdinalIgnoreCase) || name.Equals("OrganizationId", StringComparison.OrdinalIgnoreCase) || name.Equals("IsDeleted", StringComparison.OrdinalIgnoreCase);
        }

        /// <summary>
        /// 获取关键字段名称(如果给定字段是关键字段)
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public static string GetIfKeyWord(string name)
        {
            if (name.Equals("CreateTime", StringComparison.OrdinalIgnoreCase))
            {
                return "CreateTime";
            }

            if (name.Equals("Creater", StringComparison.OrdinalIgnoreCase))
            {
                return "Creater";
            }

            if (name.Equals("UpdateTime", StringComparison.OrdinalIgnoreCase))
            {
                return "UpdateTime";
            }

            if (name.Equals("Updater", StringComparison.OrdinalIgnoreCase))
            {
                return "Updater";
            }

            if (name.Equals("IsDeleted", StringComparison.OrdinalIgnoreCase))
            {
                return "IsDeleted";
            }

            if (name.Equals("OrganizationId", StringComparison.OrdinalIgnoreCase))
            {
                return "OrganizationId";
            }
            return null;
        }
    }
}
